pp108 : insertRow() Method

insertRow() Method


This method publishes arowDatanode to the XGrid. The node itself is not automatically added to the XML of the XGrid, and must be added manually. TherowDatanode must have the same parent as all the otherrowDatanodes, before the insertRow method can be called.

After the new node is inserted, the row is scrolled into view. The focus is set on the first cell of the new row.

Syntax

xgridId.insertRow(newRowData)

Parameters

Parameter Description
newRowData Required. The newly addedrowDatanode.


Return Value


Returns the row object of the new row. For details, see row object. It returns null when the row is not added.

Remarks


The newrowDatanode must have the proper XML structure. It must already be available in thedataNodeof the XGrid, and should have the same parent as the otherrowDatanodes. The newrowDatamust have a businessObject. Fields such asbusinessElementsare optional.

When the newrowDatanode is the first node added to the XGrid, make sure that the XGrid already has an (empty)dataNodebound to it.

The insertRow method adds an attribute_xgrid_rowDataIdto the rowData node. This is required for XGrid to link the rowData to other row properties.

Example


The following example shows how you can use insert, in combination with delete and change, in an application.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html onapplicationready='refresh()'>
	<head>
	<title>insertRow</title>
	<script src='/cordys/wcp/application.js'></script>
	<style>
	.alignLeft
	{
		text-align:right;
	}
	</style>
	<script>
	function refresh()
	{
		bdiEmployees.reset();
		employeesGrid.bindData( bdiEmployees.data);
	}
	function save()
	{
		bdiEmployees.synchronize();
		refresh();
	}
	function insertRow()
	{alert("insert")
		var data = employeesGrid.getData();
		var parent;
		if (!data )
		{
			//data does not exist yet -> create
			//--- var dataNode = new ActiveXObject('Microsoft.XMLDOM');
			var dataNode=cordys.loadXMLDocument("</data>")
//debugger;
			//--var topNode = dataNode.createElement('data');
			//--dataNode.appendChild( topNode );
			var responseNode = dataNode.createNode(1, 'GetEmployeesObjectsResponse ', '"http://schemas.cordys.com/DemoWebServices"');
			cordys.appendXMLNode(responseNode,topNode);
			//topNode.appendChild( responseNode );
			//bind the data to the XGrid
			employeesGrid.bindData( dataNode );
			parent = responseNode;
		}
		else
		{
			parent = cordys.selectXMLNode(data,".//*[local-name()='data']/*[local-name()='GetEmployeesObjectsResponse']")
			//parent = data.selectSingleNode('data/nwd:GetEmployeesResponse');
		}
		//create new tuple
		var newTuple = bdiEmployees.create('Employees').parentNode.parentNode;
		//first the newTuple must be added to the data structure
		cordys.appendXMLNode(newTuple,parent)
		//parent.appendChild( newTuple );
		//now the newTuple can be published to the XGrid
		employeesGrid.insertRow( newTuple );
	}
	function deleteRows()
	{
		var rows = employeesGrid.getCheckedRows();
		if ( rows.length>0 &amp;&amp; confirm('Are you sure you want to delete the checked rows') )
		{
			for ( var i=0 ; i<rows.length ; i++)
			{
				bdiEmployees.remove(rows[i].businessObject);
			}
			save();
		}
	}
		function handleDataBind()
	{
		var evnt = window.application.event;
		evnt.className = 'alignLeft';
	}
		function handleOnchange()
		{
			var evnt = window.application.event;
			var tuple = evnt.rowData;
		//	var newNode = tuple.selectSingleNode('nwd:new');
			var newNode = cordys.selectXMLNode(tuple,".//*[local-name()='new']");
			
			if (!newNode )
			{
				var newNode = tuple.ownerDocument.createNode(1, 'new', tuple.namespaceURI);
	 cordys.appendXMLNode(cordys.cloneXMLNode(evnt.businessObject),newNode );
			//	newNode.appendChild(evnt.businessObject.cloneNode(true) );
				var attrSyncId = tuple.ownerDocument.createNode(2, 'clientattr:sync_id', 'http://schemas.cordys.com/General/ClientAttributes/');
				attrSyncId.text = '0';
				tuple.setAttributeNode(attrSyncId);
				//tuple.appendChild(newNode);
				cordys.appendXMLNode(newNode,tuple)
			}
	}
	</script>
	<script type="cordys/xml" id="details">  
		<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
			<SOAP:Body>
			<GetEmployeesObjects xmlns="http://schemas.cordys.com/DemoWebServices">
				<fromEmployeeID>1</fromEmployeeID>
				<toEmployeeID>10</toEmployeeID>
			</GetEmployeesObjects>
			</SOAP:Body>
		</SOAP:Envelope>
	</script>
	</head>
	<body>
		<div  cordysType="wcp.library.data.BusDataIsland" async='false' id='bdiEmployees' request='details.XMLDocument'> </div>
		<button onclick='save()' title='Refresh'>
		<img align='absmiddle' height='15' src='/cordys/wcp/theme/default/icon/action/save.png' width='16'/>
		</button>
		<button onclick='insertRow()' title='Insert'>
		<img align='absmiddle' height='15' src='/cordys/wcp/theme/default/icon/action/new.png' width='16'/>
		</button>
		<button onclick='deleteRows()'  title='Delete'>
		<img align='absmiddle' height='15' src='/cordys/wcp/theme/default/icon/action/delete.png' width='16'/>
		</button>
		<button onclick='refresh()' title='Refresh'>
		<img align='absmiddle' height='15' src='/cordys/wcp/theme/default/icon/action/refresh.png' width='16'/>
		</button> <br />
		<div cordysType="wcp.library.ui.XGrid" 
			id='employeesGrid' 
			xpathRowData = ".//*[local-name()='data']/*[local-name()='GetEmployeesObjectsResponse']/*[local-name()='tuple']";
			xpathBusinessObject = ".//*[local-name()='Employees']"
			.[not(new)]/old/Employees' style='width:600;height:180'>
			<div id='EmployeeID' ref=".//*[local-name()='EmployeeID']" dataType='integer' onchange='handleOnchange()' onbeforedatabind='handleDataBind()'>EmployeeID</div>
			<div id='FirstName' ref=".//*[local-name()='FirstName']" onchange='handleOnchange()'>FirstName</div>
			<div id='LastName' ref=".//*[local-name()='LastName']"  fieldType='input' onchange='handleOnchange()'>LastName</div>
			<div id='City' ref=".//*[local-name()='City']" fieldType='input' onchange='handleOnchange()'>City</div>
		</div>
	</body>
</html>

See Also


xgrid, onchange, refresh()